package com.example.boot.rabbitmq.producer.demo.config.topic;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;

/**
 * direct配置
 * @author root
 * @date 2021-03-06 14:21
 */
//@Configuration
@RequiredArgsConstructor
public class RabbitTopicConfig {


    private final RabbitTopicProperties rabbitTopicProperties;

    /**
     * 配置diorect类型交换器
     * @return 交换器
     */
    @Bean
    public TopicExchange topicExchangeNew(){
        return new TopicExchange(rabbitTopicProperties.getTopicExchange());
    }

    /**
     * 声明一个持久化的队列
     * @return 声明队列
     */
    @Bean
    public Queue topicQueue() {
        return QueueBuilder.durable(rabbitTopicProperties.getTopicQueue()).build();
    }

    /**
     * 队列交换机绑定
     * @param topicExchangeNew 交换器
     * @param topicQueue 队列
     * @return 绑定信息
     */
    @Bean
    public Binding topicBindingNew(TopicExchange topicExchangeNew, Queue topicQueue) {
        return BindingBuilder.bind(topicQueue)
                .to(topicExchangeNew)
                .with(rabbitTopicProperties.getTopicKey());
    }



}
